package com.adcok.lcdns.cronos.parser;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

import com.adcok.lcdns.cronos.data.CNLottoAdLottoData;
import com.adcok.lcdns.cronos.datahandler.CNBaseDataParser;
import com.adcok.lcdns.cronos.datahandler.CNResultSet;

public class CNLottoParser extends CNBaseDataParser{
	protected void onParseContent(Element xmlObject, CNResultSet resultSet)
			throws Exception {
		
		NodeList nodeList = xmlObject.getElementsByTagName("advertising");
		NodeList nodeSendSeq = xmlObject.getElementsByTagName("sendSeq");
		
		NodeList nodeMainUrl = xmlObject.getElementsByTagName("mainUrl"); 
		
		NodeList nodeNum1 = xmlObject.getElementsByTagName("num1");
		NodeList nodeNum2 = xmlObject.getElementsByTagName("num2");
		NodeList nodeNum3 = xmlObject.getElementsByTagName("num3");
		NodeList nodeNum4 = xmlObject.getElementsByTagName("num4");
		NodeList nodeNum5 = xmlObject.getElementsByTagName("num5");
		NodeList nodeNum6 = xmlObject.getElementsByTagName("num6");
		
		String lottoNum1 = nodeNum1.item(0).getFirstChild().getNodeValue();
		String lottoNum2 = nodeNum2.item(0).getFirstChild().getNodeValue();
		String lottoNum3 = nodeNum3.item(0).getFirstChild().getNodeValue();
		String lottoNum4 = nodeNum4.item(0).getFirstChild().getNodeValue();
		String lottoNum5 = nodeNum5.item(0).getFirstChild().getNodeValue();
		String lottoNum6 = nodeNum6.item(0).getFirstChild().getNodeValue();
		String sendSeq = nodeSendSeq.item(0).getFirstChild().getNodeValue();
		
		resultSet.setmLottoNum1(lottoNum1);
		resultSet.setmLottoNum2(lottoNum2);
		resultSet.setmLottoNum3(lottoNum3);
		resultSet.setmLottoNum4(lottoNum4);
		resultSet.setmLottoNum5(lottoNum5);
		resultSet.setmLottoNum6(lottoNum6);
		resultSet.setmSendSeq(sendSeq);
		
		int count = nodeList.getLength();
		
		for (int i = 0; i < count; i++)
		{
			Element elementData = (Element) nodeList.item(i);
			if (elementData == null)
				continue;
			
			CNLottoAdLottoData dataSet = new CNLottoAdLottoData();
			
			if(nodeMainUrl.item(i).getFirstChild() != null)
				dataSet.adContents = nodeMainUrl.item(i).getFirstChild().getNodeValue();
			
			resultSet.addDataSet(dataSet);
		}
	}
}
